package cn.paging.util;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtils
{
	private static SessionFactory sessionFactory;

	static
	{
		try
		{
			Configuration cfg = new Configuration().configure();
			
			sessionFactory=cfg.buildSessionFactory();
			
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}

	public static SessionFactory getSessionFactory()
	{
		return sessionFactory;
	}

	public static void setSessionFactory(SessionFactory sessionFactory)
	{
		HibernateUtils.sessionFactory = sessionFactory;
	}
	
	public static Session getSession()
	{
		return sessionFactory.openSession();
	}
	
	public static void closeSession(Session session)
	{
		if(null != session)
		{
			if(session.isOpen())
			{
				session.close();
			}
		}
	}
	
	

}
